package day24;

import java.util.InputMismatchException;
import java.util.Scanner;

/**
 * 异常类的测试
 * @author yyfei
 *
 */
public class ExceptionTest {
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		
		try {
			System.out.println("请输入a:");
			double a=scanner.nextDouble();
			System.out.println("请输入b:");
			double b=scanner.nextDouble();
			double c= chufa(a, b);
			System.out.println(c);
		}catch (NumberFormatException e) {
			// TODO: handle exception
			System.out.println("输入的数据格式不正确");
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		
		
	}
	
	
	public static double chufa(double a,double b) throws MyException {
		if (a<0 ||b<0) {
			throw new MyException("输入的数据必须时正整数！");	
		} else {
			return a/b;
		}
	}
	
	
}
